#!/usr/bin/python
# -*- coding: UTF-8 -*-
# author : bird.zhang@ximalaya.com

import random
import zlib

db_name = 'microlesson'
table_name = 'tb_favorite'
table_cnt = 10
file_name = "out.sql"

create_node_table_template = """
DROP TABLE IF EXISTS `{db_name}`.`{table_name}_node`;
CREATE TABLE `{db_name}`.`{table_name}_node`(
	`id` INT(11) NOT NULL AUTO_INCREMENT, 
	`node` INT(11) UNSIGNED NOT NULL, 
	`table_name` VARCHAR(255) NOT NULL, 
	`created_at` DATETIME NOT NULL, 
	`updated_at` DATETIME NOT NULL, 
	PRIMARY KEY (`id`), 
	KEY `idx_tb_favorite` (`node`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
"""


def gen_random_len():
    return int(random.random() * 9 + 8)


hex_chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']


def gen_random_hex_str(str_len):
    _str = ''
    for i in range(str_len):
        _index = int(random.random() * len(hex_chars))
        _str += str(hex_chars[_index])

    return _str


for i in range(10):
    str_len = gen_random_len()
    random_hex_str = gen_random_hex_str(str_len)
    print(zlib.crc32(bytes(random_hex_str, encoding="utf8")))
